<?php

namespace App\Models;

use App\Enums\AvailableStatus;
use App\Enums\OngoingStatus;
use BenSampo\Enum\Traits\CastsEnums;
use Carbon\Carbon;

/**
 * @mixin IdeHelperInvitationActivity
 */
class InvitationActivity extends BaseModel
{
    use CastsEnums;

    protected $casts = [
        'status' => AvailableStatus::class,
    ];

    protected $appends = [
        'start_date',
        'end_date',
    ];

    public function registers()
    {
        return $this->hasMany(InvitationRegister::class, 'activity_id');
    }

    public function getStartDateAttribute()
    {
        return Carbon::parse($this->start_time)->toDateString();
    }

    public function getEndDateAttribute()
    {
        return Carbon::parse($this->end_time)->toDateString();
    }

    public function getOnGoingStatus()
    {
        if (now()->lt($this->start_time)) {
            return OngoingStatus::NOT_START();
        }
        if (now()->gt($this->end_time)) {
            return OngoingStatus::FINISHED();
        }

        return OngoingStatus::ON_GOING();
    }

    public function agent()
    {
        return $this->belongsTo(Agent::class);
    }
}
